package exp.parser;

import word.parser.WordElement;

public abstract class UnaryExp extends ExpParser {

    public UnaryExp(boolean isComputable, boolean isConst) {
        super(isComputable, isConst);

    }

    public static ExpParser parseUnaryExp() {
        if (getAnalyzingWord().getType() == WordElement.WordType.IDENFR &&
                getAnalyzingWord(1).getType() == WordElement.WordType.LPARENT) {
            return FuncExp.parseFuncExp();
        } else if (getAnalyzingWord().getType() == WordElement.WordType.NOT ||
                getAnalyzingWord().getType() == WordElement.WordType.PLUS ||
                getAnalyzingWord().getType() == WordElement.WordType.MINU) {
            if (getAnalyzingWord().getType() == WordElement.WordType.NOT) {
                analyzeNextWord();
                return new NotExp(UnaryExp.parseUnaryExp());
            } else if (getAnalyzingWord().getType() == WordElement.WordType.PLUS) {
                analyzeNextWord();
                return UnaryExp.parseUnaryExp();
            } else {
                analyzeNextWord();
                return new MulExp(new IntConstExp(-1), UnaryExp.parseUnaryExp(), MulExp.MulOpt.MULT);
            }
        }
        return PrimaryExp.parsePrimaryExp();
    }
}
